package com.zhang.controller.warehouse;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.zhang.common.util.result.R;
import com.zhang.common.util.result.RUtils;
import com.zhang.warehouse.entity.WareInfo;
import com.zhang.warehouse.entity.WareSku;
import com.zhang.warehouse.service.IWareInfoService;
import com.zhang.warehouse.service.IWareSkuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/warehouse/")
public class WarehouseController {
    @Autowired
    private IWareInfoService wareInfoService;
    @Autowired
    private IWareSkuService wareSkuService;

    @PostMapping("add/wareInfo")
    public R addWareInfo(@RequestBody WareInfo wareInfo) {
        wareInfoService.save(wareInfo);
        return RUtils.successMsg("新增成功");
    }

    @GetMapping("get/wareInfo/list/page/{pageNum}/{pageSize}")
    public R getWareInfoListPage(@PathVariable Integer pageNum, @PathVariable Integer pageSize, @RequestParam Map<String, Object> wareInfoSearchDto) {
        IPage page = wareInfoService.getWareInfoListPage(pageNum, pageSize, wareInfoSearchDto);
        return RUtils.successData(page);
    }
    @GetMapping("get/wareInfo/list")
    public R getWareInfoList() {
        List<WareInfo> list = wareInfoService.list();
        return RUtils.successData(list);
    }
    @PostMapping("add/wareSku")
    public R addWareSku(@RequestBody WareSku wareSku) {
        wareSkuService.save(wareSku);
        return RUtils.successMsg("新增成功");
    }

    @GetMapping("get/wareSku/list/page/{pageNum}/{pageSize}")
    public R getWareSkuListPage(@PathVariable Integer pageNum, @PathVariable Integer pageSize, @RequestParam Map<String, Object> wareSkuSearchDto) {
        IPage page = wareSkuService.getWareSkuListPage(pageNum, pageSize, wareSkuSearchDto);
        return RUtils.successData(page);
    }
    @GetMapping("get/wareSku/list")
    public R getWareSkuList() {
        List<WareSku> list = wareSkuService.list();
        return RUtils.successData(list);
    }

    /**获取运费
     * @param addressId 收货地址id
     * @return {@link R}
     */
    @GetMapping("get/freight")
    public R getFreight(@RequestParam Long addressId){
       BigDecimal freight= wareInfoService.getFreightByAddressId(addressId);
       return RUtils.successData(freight);
    }
}
